window.onload = function() {
  var vm = new Vue({
    el: "#layout-a",
    data: {
      houseList: [],
      houseCollectionNum: [],
      countVisitsLisst: []
    },
    created: function() {
      this.findById();
    },
    methods: {
      toDetail(house){
        window.open("/three/household.html?name="+house.building3dNo+"&hsid="+house.roomNo+"&houseid="+house.id+"&buildid="+house.buildingId)
      },
      //  获取微活动房源列表
      findById: function() {
        this.houseCollectionNum = [];
        var _this = this;
        var id = this.getParams("id");
        house_server.findById({ id: id }, function(data) {
          var collectList = [];
          _this.houseList = data.data.list;
          for (var i = 0; i < data.data.list.length; i++) {
            collectList.push(data.data.list[i].id);
          }
          setTimeout(function() {
            _this.getCountVisits(collectList, 1);
            _this.getHouseCollectionNums(collectList);
          }, 500);
        });
      },
      // 收藏(多)
      getHouseCollectionNums: function(idList) {
        var $this = this;
        house_server.getHouseCollectionNums(
          {
            houseIds: idList
          },
          function(res) {
            $this.houseCollectionNum = res.data;
          }
        );
      },
      //统计浏览量多个
      getCountVisits: function(list, types) {
        var $this = this;
        house_server.getCountVisits(
          {
            ids: list,
            type: 2
          },
          function(data) {
            if (types == 1) {
              $this.countVisitsLisst = data.data;
            } else {
              $this.countVisitsLisst2 = data.data;
            }
          }
        );
      },
      //图片解析
      getImgUrl: function() {
        var ip = window.location.host,
          url = "";
        if (ip.indexOf("127.0.0.1") >= 0 || ip.indexOf("localhost") >= 0) {
          url = "http://114.113.68.14:9000/image/";
        } else if (ip.indexOf("www.") >= 0) {
          url = "http://image.3dzhixuan.com/image/";
        } else {
          url = "http://" + ip + "/image/";
        }
        return url;
      },
      // 获取参数
      getParams(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
      },
      // 转化时间
      forDate: function(time) {
        var timestamp = (new Date(time.replace(/-/g, "/")) * 1) / 1000;
        function zeroize(num) {
          return (String(num).length == 1 ? "0" : "") + num;
        }
        var curTimestamp = parseInt(new Date().getTime() / 1000); //当前时间戳
        var timestampDiff = curTimestamp - timestamp; // 参数时间戳与当前时间戳相差秒数
        var curDate = new Date(curTimestamp * 1000); // 当前时间日期对象
        var tmDate = new Date(timestamp * 1000); // 参数时间戳转换成的日期对象

        var Y = tmDate.getFullYear(),
          m = tmDate.getMonth() + 1,
          d = tmDate.getDate();
        var H = tmDate.getHours(),
          i = tmDate.getMinutes(),
          s = tmDate.getSeconds();
        if (timestampDiff < 60) {
          // 一分钟以内
          return "刚刚";
        } else if (timestampDiff < 3600) {
          // 一小时前之内
          return Math.floor(timestampDiff / 60) + "分钟前";
        } else if (
          curDate.getFullYear() == Y &&
          curDate.getMonth() + 1 == m &&
          curDate.getDate() == d
        ) {
          return "今天" + zeroize(H) + ":" + zeroize(i);
        } else {
          var newDate = new Date((curTimestamp - 86400) * 1000); // 参数中的时间戳加一天转换成的日期对象
          if (
            newDate.getFullYear() == Y &&
            newDate.getMonth() + 1 == m &&
            newDate.getDate() == d
          ) {
            return "昨天" + zeroize(H) + ":" + zeroize(i);
          } else if (curDate.getFullYear() == Y) {
            return (
              zeroize(m) +
              "月" +
              zeroize(d) +
              "日 " +
              zeroize(H) +
              ":" +
              zeroize(i)
            );
          } else if (timestampDiff < 259200000) {
            return Math.floor(timestampDiff / 86400000) + "天前";
          } else {
            return (
              Y +
              "年" +
              zeroize(m) +
              "月" +
              zeroize(d) +
              "日 " +
              zeroize(H) +
              ":" +
              zeroize(i)
            );
          }
        }
      }
    }
  });
};
